// License Notification
//======================================================
// Copyright (c) 2010 Channel Intelligence Inc.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// ======================================================




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CIP4.Common;

namespace CIP4.Browser
{
    class ListBoxLogEntryType
    {
        public MajorEnum Status { get; set; }
        public MinorEnum MinorStatus { get; set; }
        public string Message { get; set; }
        public object[] Paras { get; set; }
        public LoggerResponseEnum Response { get; set; }
        public DateTime DeliveryTime { get; set; }
        public string ToLongString()
        {
            return string.Format("{0} - {1}.{2} {3}", DeliveryTime.ToString("HH:mm:ss"), Status, MinorStatus, string.Format(Message, Paras));
        }
        public override string ToString()
        {
            return string.Format("{0} - {1}.{2} {3} {4}", DeliveryTime.ToString("HH:mm:ss"), Status, MinorStatus, Message, ObjectArrayToString(Paras, 60));
        }

        private string ObjectArrayToString(object[] paras, int truncateTo)
        {
            string text = "{";
            string sep = string.Empty;
            foreach (object value in paras)
            {
                text += sep + value.ToString();
                sep = ",";
            }
            if (text.Length > truncateTo)
                text = text.Substring(0, truncateTo) + "...";
            return text + "}";
        }

    }
}
